// 引入全局函数
const app = getApp();
Component({
 properties: {
   data: {
     type: Number,
     value: 0,
   }
 },
  data: {
    cartCount:null,
    selected: 0,
    color: "#6e6d6b",
    selectedColor: "#c6b494",
    backgroundColor: "#F7F8F8",
    list: [
      {
        pagePath: "/pages/index/index",
        iconPath: "/images/tabBar/index-b.png",
        selectedIconPath: "/images/tabBar/c6b494/index.png",
        text: "首页"
      },
      {
        pagePath: "/pages/category/category",
        iconPath: "/images/tabBar/order-b.png",
        selectedIconPath: "/images/tabBar/c6b494/order.png",
        text: "产品"
      },
      {
        pagePath: "/pages/order/order",
        iconPath: "/images/tabBar/car-b.png",
        selectedIconPath: "/images/tabBar/c6b494/cart.png",
        text: "配置清单",
        hasBadge: true
      },
      {
        pagePath: "/pages/home/home",
        iconPath: "/images/tabBar/home-b.png",
        selectedIconPath: "/images/tabBar/c6b494/home.png",
        text: "我的"
      },
    ],
  },
  ready: function () {
    this.setData({
      selected: app.globalData.selected,
    });
  },
  onShow() {
    const cartCount = wx.getStorageSync('cartCount')
    this.setData({
      cartCount: cartCount
    });
  },
  /**
   * 组件的方法列表
   */
  methods: {
    switchTab(e) {
      const data = e.currentTarget.dataset;
      const url = data.path;
      // 这里是存放在全局得变量因为tabbar需要再全局使用，所以需要用一个全局变量存起来
      app.globalData.selected = data.index;
      wx.switchTab({ url });
    },
  },
});
